package com.ruoyi.swla2.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.swla2.bo.DeviceLedgerBo;
import com.ruoyi.swla2.bo.TaskDetailBo;
import com.ruoyi.swla2.domain.TaskDetail;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.swla2.domain.DeviceLedger;
import com.ruoyi.swla2.service.IDeviceLedgerService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 设备台账Controller
 *
 * @author gdqt
 * @date 2025-06-26
 */
@RestController
@RequestMapping("/swla2/deviceLedger")
public class DeviceLedgerController extends BaseController
{
    @Autowired
    private IDeviceLedgerService deviceLedgerService;

    /**
     * 查询设备台账列表
     */
    @PreAuthorize("@ss.hasPermi('swla2:deviceLedger:list')")
    @GetMapping("/list")
    public TableDataInfo list(DeviceLedger deviceLedger)
    {
        startPage();
        List<DeviceLedger> list = deviceLedgerService.selectDeviceLedgerList(deviceLedger);
        return getDataTable(list);
    }


    @PreAuthorize("@ss.hasPermi('swla2:deviceLedger:list')")
    @GetMapping("/listDetailMore")
    public TableDataInfo listDetailMore(DeviceLedgerBo deviceLedgerBo)
    {
        startPage();
        List<DeviceLedgerBo> list = deviceLedgerService.listDetailMore(deviceLedgerBo);
        return getDataTable(list);
    }


    /**
     * 导出设备台账列表
     */
    @PreAuthorize("@ss.hasPermi('swla2:deviceLedger:export')")
    @Log(title = "设备台账", businessType = BusinessType.EXPORT)
    @PostMapping("/exportMore")
    public void exportMore(HttpServletResponse response, DeviceLedgerBo deviceLedgerBo)
    {
        List<DeviceLedgerBo> list = deviceLedgerService.listDetailMore(deviceLedgerBo);
        ExcelUtil<DeviceLedgerBo> util = new ExcelUtil<DeviceLedgerBo>(DeviceLedgerBo.class);
        util.exportExcel(response, list, "任务详情数据");
    }







    /**
     * 导出设备台账列表
     */
    @PreAuthorize("@ss.hasPermi('swla2:deviceLedger:export')")
    @Log(title = "设备台账", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DeviceLedger deviceLedger)
    {
        List<DeviceLedger> list = deviceLedgerService.selectDeviceLedgerList(deviceLedger);
        ExcelUtil<DeviceLedger> util = new ExcelUtil<DeviceLedger>(DeviceLedger.class);
        util.exportExcel(response, list, "设备台账数据");
    }

    /**
     * 获取设备台账详细信息
     */
    @PreAuthorize("@ss.hasPermi('swla2:deviceLedger:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(deviceLedgerService.selectDeviceLedgerById(id));
    }

    /**
     * 新增设备台账
     */
    @PreAuthorize("@ss.hasPermi('swla2:deviceLedger:add')")
    @Log(title = "设备台账", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DeviceLedger deviceLedger)
    {
        return toAjax(deviceLedgerService.insertDeviceLedger(deviceLedger));
    }

    /**
     * 修改设备台账
     */
    @PreAuthorize("@ss.hasPermi('swla2:deviceLedger:edit')")
    @Log(title = "设备台账", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DeviceLedger deviceLedger)
    {
        return toAjax(deviceLedgerService.updateDeviceLedger(deviceLedger));
    }

    /**
     * 删除设备台账
     */
    @PreAuthorize("@ss.hasPermi('swla2:deviceLedger:remove')")
    @Log(title = "设备台账", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(deviceLedgerService.deleteDeviceLedgerByIds(ids));
    }




    @GetMapping("/listForGJAddLedger")
    public TableDataInfo listForGJAddLedger(DeviceLedgerBo deviceLedgerBo)
    {
        startPage();
        deviceLedgerBo.setTenantId(getLoginUser().getTenantId());
        List<DeviceLedger> list = deviceLedgerService.listForGJAddLedger(deviceLedgerBo);
        return getDataTable(list);
    }




}
